home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / SML⁄NJ 93+ / Documentation / examples / quicksort.sml < prev    next >
Encoding:
Text File  |  1995-12-30  |  475 b   |  13 lines  |  [TEXT/R*ch]

  1.  fun quick(le:'a*'a->bool) =
  2.     let fun sort [] = []
  3.            | sort [x] = [x]
  4.            | sort (a::rest) = (* the head "a" is the pivot *)
  5.                let fun split(left,right,[]) = sort left @ (a::sort right)
  6.                         | split(left,right,x::l) =
  7.                          if le(x,a) then split(x::left,right,l)
  8.                                     else split(left,x::right,l)
  9.                in split([],[],rest)
  10.               end
  11.       in sort
  12.      end;
  13.